package cool.taomu.toolkit.stock

import com.google.auto.service.AutoService
import com.google.common.reflect.TypeToken
import com.google.inject.Key
import com.google.inject.TypeLiteral
import com.google.inject.name.Names
import cool.taomu.toolkit.platform.inter.AbsPlatform
import cool.taomu.toolkit.platform.inter.IPlatform
import cool.taomu.toolkit.utils.FileTools
import java.util.List
import org.slf4j.LoggerFactory
import com.google.gson.Gson
import org.apache.commons.io.FileUtils
import java.io.File
import org.apache.commons.vfs2.FileSystemManager
import org.apache.commons.io.IOUtils
import cool.taomu.toolkit.TaomuConfigure

@AutoService(IPlatform)
class StockPlugin extends AbsPlatform {
    val static LOG = LoggerFactory.getLogger(StockPlugin);

    override init() {
        FileTools.unpackWar(StockPlugin, #["static", "template", "config"]);
        // 添加Menu
        var injector = this.context.injectorSupplier.get()
        try(var fobject = injector.getInstance(FileSystemManager).resolveFile("res://config/stock_menu.json")) {
            var json = IOUtils.toString(fobject.content.inputStream, "UTF-8");
            var type = injector.getInstance(Key.get(TypeToken, Names.named("taomu.menu.type")))
            var mList = injector.getInstance(Key.get(new TypeLiteral<List<Object>>() {
            }, Names.named("taomu.menu.list")))
            mList.add(new Gson().fromJson(json, type.rawType));
            LOG.info("type:{}", mList)
        }
    }

    override module(TaomuConfigure configure) {
    }

    override note() {
        "股票插件"
    }

    override packages() {
        "cool.taomu.toolkit.stock.controller"
    }

    override start() {
    }

    

}
